package com.ayg.controller;

import com.ayg.pojo.Photo;
import com.ayg.service.PhotoService;
import com.ayg.vo.ImageVO;
import com.ayg.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/photo")
@CrossOrigin
public class PhotoController {

    @Autowired
    private PhotoService photoService;

    /**
     * 查询创建好的相册
     * @return  list集合
     */
    @GetMapping("/getPhotoList")
    public SysResult getPhotoList(){
        List<Photo> list=photoService.getPhotoList();
        return SysResult.success(list);
    }


    /**
     * 业务说明：相册创建
     * url地址：/photoCat/savePhoto
     * 请求参数：整个from表单  json串
     * 返回值： SysResult对象
     */
    @PostMapping("/savePhoto")
    public SysResult savePhotoCat(@RequestBody Photo photo){
        Integer savePhoto = photoService.savePhoto(photo);
        return SysResult.success(savePhoto);
    }

    /**
     * 业务说明：上传图片
     * url地址：/photoCat/savePhoto
     * @param photo
     * @return
     */
    @PostMapping("/imageUpload")
    public SysResult imageUpload(@RequestBody Photo photo){
        photoService.imageUpload(photo);
        return SysResult.success();
    }

    @PutMapping("/photoUpload")
    public SysResult photoUpload(@RequestBody Photo photo){
        photoService.photoUpload(photo);
        return SysResult.success();
    }

    /**
     * 图片预览
     */
    @GetMapping("/getBrowsePhotoList")
    public SysResult getBrowsePhotoList(String photoName){
        List<Photo> list=photoService.getBrowsePhotoList(photoName);
        return SysResult.success(list);
    }

}
